﻿using System.Linq;

namespace TicTacToe.Core.AI
{
    static partial class Conditions
    {
        static ConditionResult InnerCube(AIGameField field, int player, int x, int y, int z)
        {
            return (new[] { x, y, z }).All(i => i == 1 || i == 2) ?
                ConditionResult.InInnerCube : ConditionResult.None;
        }

        static ConditionResult Random(AIGameField field, int player, int x, int y, int z)
        {
            return rand.NextDouble() >= 0.95 ? ConditionResult.Random : ConditionResult.None;
        }

        static ConditionResult CornerField(AIGameField field, int player, int x, int y, int z)
        {
            if (x == 0 && y == 0 ||
                x == 0 && y == 3 ||
                x == 3 && y == 0 ||
                x == 3 && y == 3)
                return ConditionResult.CornerField;
            return ConditionResult.None;
        }

        static ConditionResult MiddleField(AIGameField field, int player, int x, int y, int z)
        {
            if (x == 1 && y == 1 ||
                x == 1 && y == 2 ||
                x == 2 && y == 1 ||
                x == 2 && y == 2)
                return ConditionResult.InMiddle;
            return ConditionResult.None;
        }

        static ConditionResult NextToOwnField(AIGameField field, int player, int x, int y, int z)
        {
            for (int i = x - 1; i < x + 1; i++)
                for (int j = y - 1; j < y + 1; j++)
                    for (int k = z - 1; k < z + 1; k++)
                        if (field[i, j, k] == player)
                            return ConditionResult.NextToOwnField;
            return ConditionResult.None;
        }
    }
}
